<template>
	<view class="goods_deta">
		<uv-navbar placeholder autoBack bgColor="#CA1C1D">
			<template v-slot:left>
				<view class="left_slot">
					<image src="@/static/images/back.png"></image>
				</view>
			</template>
			<template v-slot:center>
				<view class="nav_title">商品详情</view>
			</template>
			<!-- <template v-slot:right>
				<view class="right_slot">
					<image src="@/static/images/fx.png"></image>
				</view>
			</template> -->
		</uv-navbar>
		<scroll-view scroll-y class="scroll_view">
			<uv-swiper :list="rotation" keyName="img" radius="0" imgMode="scaleToFill" height="375"></uv-swiper>
			<view class="info">
				<view class="name">{{data_info.name}}</view>
				<view class="synopsis">{{data_info.synopsis}}</view>
				<view class="price">
					<view class="unit">￥</view>
					<view class="value">{{data_info.price}}</view>
				</view>
			</view>
			<view class="cell_view">
				<view class="item">
					<view class="key">运费</view>
					<view class="value" v-if="data_info.freight>0">{{data_info.freight}}</view>
					<view class="value" v-else>包邮</view>
				</view>
				<!-- <view class="item">
					<view class="key">优惠</view>
					<view class="value">购买赠送积分 会员优惠10</view>
					<image src="@/static/images/c13.png" class="icon"></image>
				</view> -->
				<view class="item" @click="open">
					<view class="key">数量</view>
					<view class="value">请选择数量</view>
					<image src="@/static/images/c13.png" class="icon"></image>
				</view>
			</view>
			<view class="title">商品详情</view>
			<view class="parse_view">
				<uv-parse :preview-img="false" :content="data_info.content"></uv-parse>
			</view>
		</scroll-view>
		<view class="footer">
			<view class="left">
				<!-- <view class="item">
					<image src="@/static/images/c14.png"></image>
					<text>购物车</text>
				</view> -->
				<view class="item" @click="goTabbar">
					<image src="@/static/images/c15.png"></image>
					<text>首页</text>
				</view>
			</view>
			<view class="right">
				<!-- <view class="item">加入购物车</view> -->
				<view class="item" @click="open">立即购买</view>
			</view>
		</view>
		<uv-popup ref="popup" mode="bottom">
			<Popup :data_info="data_info" @close="popup.close()" @submit="submit" />
		</uv-popup>
	</view>
</template>

<script setup>
	import {
		productInfo,
		orderPlace
	} from "@/request/api";
	import Popup from "@/components/goods/Popup.vue";
	import useBase from "@/hooks/useBase.js";
	const {
		router
	} = useBase();
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import {
		ref,
		shallowRef
	} from "vue";

	const goTabbar = () => {
		uni.switchTab({
			url: '/'
		})
	};
	const popup = shallowRef();
	const open = () => popup.value.open();
	const submit = async (value) => {
		popup.value.close();
		router(`/pages/club/confirm_order?id=${data_info.value.id}&number=${value}`)
	};
	const rotation = ref([]);
	const data_info = ref({
		id: "",
		name: "",
		price: 0.00,
		freight: 0.00,
		stock: 0,
		content: "",
	});
	onLoad(async ({
		id
	}) => {
		let {
			data
		} = await productInfo({
			id
		});
		rotation.value = data.imgs;
		data_info.value = data;
	});
</script>

<style scoped lang="scss">
	.goods_deta {
		min-height: calc(100vh - var(--window-top) - var(--window-bottom));
		background-color: #f5f5f5;

		.left_slot {
			image {
				width: 43rpx;
				height: 36rpx;
			}
		}

		.nav_title {
			color: #F5F5F5;
			font-size: 36rpx;
		}

		.right_slot {
			image {
				width: 32rpx;
				height: 32rpx;
			}
		}

		.scroll_view {
			height: calc(100vh - var(--window-top) - #{$navBarHeight} - var(--window-bottom) - 100rpx);

			.info {
				height: 285rpx;
				background: #FFFFFF;
				padding: 36rpx 56rpx 54rpx 42rpx;
				box-sizing: border-box;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.name {
					line-height: 36rpx;
					color: #333333;
					font-size: 30rpx;
					font-weight: bold;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}

				.synopsis {
					color: #999999;
					font-size: 24rpx;
				}

				.price {
					display: flex;
					align-items: flex-end;

					.unit {
						color: #CA1C1D;
						font-size: 32rpx;
						font-weight: bold;
					}

					.value {
						color: #CA1C1D;
						font-size: 50rpx;
						font-weight: bold;
					}
				}
			}

			.cell_view {
				margin: 20rpx 0;
				padding: 0 30rpx;
				box-sizing: border-box;
				background: #FFFFFF;

				.item {
					height: 100rpx;
					border-bottom: 2rpx solid #EEEEEE;
					box-sizing: border-box;
					display: flex;
					justify-content: space-between;
					align-items: center;

					&:last-child {
						border-bottom: none;
					}

					&:nth-child(2) {
						.value {
							color: #CA1C1D;
						}
					}

					.key {
						color: #333333;
						font-size: 30rpx;
						font-weight: bold;
					}

					.value {
						flex: 1;
						text-align: right;
						color: #666666;
						font-size: 26rpx;
						padding-right: 20rpx;
						box-sizing: border-box;
					}

					.icon {
						width: 20rpx;
						height: 20rpx;
					}
				}
			}

			.title {
				height: 94rpx;
				line-height: 94rpx;
				color: #333333;
				font-size: 36rpx;
				font-weight: bold;
				padding-left: 40rpx;
				box-sizing: border-box;
				background: #FFFFFF;
			}

			.parse_view {
				background: #FFFFFF;
				// line-height: 48rpx !important;
				// color: #999999;
				// font-size: 28rpx;
				// padding: 30rpx;
				// box-sizing: border-box;
			}
		}

		.footer {
			height: 100rpx;
			padding: 0 30rpx;
			box-sizing: border-box;
			background-color: #FFFFFF;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.left {
				padding-right: 20rpx;
				box-sizing: border-box;
				display: flex;

				.item {
					margin-left: 48rpx;
					display: flex;
					flex-direction: column;
					align-items: center;

					&:first-child {
						margin-left: 0;
					}

					image {
						width: 40rpx;
						height: 40rpx;
					}

					text {
						color: #333333;
						font-size: 18rpx;
						padding-top: 8rpx;
						box-sizing: border-box;
					}
				}
			}

			.right {
				flex: 1;
				display: flex;

				.item {
					flex: 1;
					// width: 214rpx;
					height: 72rpx;
					border-radius: 10rpx;
					display: flex;
					justify-content: center;
					align-items: center;

					&:first-child {
						color: #000000;
						font-size: 26rpx;
						border: 2px solid #000000;
						box-sizing: border-box;
					}

					&:last-child {
						color: #FFFFFF;
						font-size: 26rpx;
						border: none;
						background: #683617;
					}
				}
			}
		}
	}
</style>